import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:open_app_settings/open_app_settings.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion = 'Unknown';;

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    final ButtonStyle style =
        ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20));
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openAppSettings();
                },
                child: const Text('设置'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openWIFISettings();
                },
                child: const Text('WLAN'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openLocationSettings();
                },
                child: const Text('定位'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openSecuritySettings();
                },
                child: const Text('隐私与安全'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openBluetoothSettings();
                },
                child: const Text('蓝牙'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openDataRoamingSettings();
                },
                child: const Text('移动数据'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openDateSettings();
                },
                child: const Text('日期'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openDisplaySettings();
                },
                child: const Text('显示与亮度'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openNotificationSettings();
                },
                child: const Text('通知'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openSoundSettings();
                },
                child: const Text('声音'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openInternalStorageSettings();
                },
                child: const Text('存储'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openBatteryOptimizationSettings();
                },
                child: const Text('电池'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openNFCSettings();
                },
                child: const Text('NFC'),
              ),
              ElevatedButton(
                style: style,
                onPressed: () async {
                  await OpenAppSettings.openAndroidCustomSetting('hotspot_data_settings');
                },
                child: const Text('个人热点'),
              )
            ]
          )
        ),
      ),
    );
  }
}
